package com.derbysoft.defender.util;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import java.lang.reflect.Type;

/**
 * <p>some description here.</p>
 * Created by Afee Lee on 2017-03-20 23:20
 *
 * @author Afee Lee
 * @version 1.0
 * @see Object
 * @since 1.8
 */
public class JsonUtil {
    private static Gson gson = new Gson();

    private static Gson prettyGson = new GsonBuilder().setPrettyPrinting().create();

    public static String toJson(Object obj) {
        return gson.toJson(obj);
    }

    public static String toPrettyJson(Object obj) {
        return prettyGson.toJson(obj);
    }

    public static <T> T fromJson(String json, Class<T> t) {
        return gson.fromJson(json, t);
    }

    public static <T> T fromJson(String json, Type t) {
        return gson.fromJson(json, t);
    }
}
